﻿using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Volo.Abp.AspNetCore.Mvc;
using YaAppoint.Appointments.ManualAppoints;
using YaAppoint.Web.Controllers.Model;

namespace YaAppoint.Web.Controllers
{
    public class ManualAppointController(IManualAppointAppService manualAppointAppService) : AbpController
    {
        private readonly IManualAppointAppService _manualAppointAppService = manualAppointAppService;

        [HttpGet("/api/manual-appoint/get-date-limit")]
        public async Task<IActionResult> GetDateLimit(Guid deviceId)
        {
            return new JsonResult(await _manualAppointAppService.GetDateLimit(deviceId));
        }

        /// <summary>
        /// 获取申请科室选项
        /// </summary>
        [HttpGet("/api/manual-appoint/get-apply-dep-options")]
        public async Task<IActionResult> GetApplyDepOptions()
        {
            return new JsonResult(await _manualAppointAppService.GetApplyDepOptions());
        }

        /// <summary>
        /// 获取选中申请项目对应的申请单列表
        /// </summary>
        [HttpGet("/api/manual-appoint/get-selected-apply-form-list")]
        public async Task<IActionResult> GetSelectedApplyFormList([FromBody] List<Guid> idList)
        {
            return new JsonResult(await _manualAppointAppService.GetSelectedApplyFormList(idList));
        }


        /// <summary>
        /// 未预约列表加载
        /// </summary>
        [HttpPost("/api/manual-appoint/get-no-appoint-apply-item-list")]
        public async Task<IActionResult> GetNoAppointmentApplyItemListAsync([FromBody] SearchModel model)
        {
            return new JsonResult(await _manualAppointAppService.GetNoAppointmentApplyItemListAsync(model.Number, model.UserData));
        }

        /// <summary>
        /// 已预约列表加载
        /// </summary>
        [HttpPost("/api/manual-appoint/get-appointed-apply-item-list")]
        public async Task<IActionResult> GetAppointedApplyItemListAsync([FromBody] SearchModel model)
        {
            return new JsonResult(await _manualAppointAppService.GetAppointedApplyItemListAsync(model.Number, model.UserData));
        }

        /// <summary>
        /// 新建号池
        /// </summary>
        [HttpPost("/api/manual-appoint/create-pool")]
        public async Task<JsonResult> CreatePool([FromBody] NewPoolDto dto)
        {
            return new JsonResult(await _manualAppointAppService.CreatePool(dto));
        }


        /// <summary>
        ///  当前科室下，特定设备类型下设备列表
        /// </summary>
        /// <param name="deviceTypeID"></param>
        [HttpGet("/api/manual-appoint/get-device-list")]
        public async Task<JsonResult> GetDeviceList(Guid deviceTypeID)
        {
            return new JsonResult(await _manualAppointAppService.GetDeviceList(deviceTypeID));
        }


        /// <summary>
        /// 获取号池列表
        /// 给定日期、给定设备
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost("/api/manual-appoint/get-pool-list")]
        public async Task<IActionResult> GetPoolList([FromBody] PoolQueryDto dto)
        {
            return new JsonResult(await _manualAppointAppService.GetPoolList(dto));
        }


        /// <summary>
        /// 提交预约
        /// </summary>
        /// <param name="examItemList"></param>
        /// <returns></returns>
        [HttpPost("/api/manual-appoint/subimt-appoint")]
        public async Task<IActionResult> SubmitAppoint([FromBody] List<SubmitAppointDto> examItemList)
        {
            return new JsonResult(await _manualAppointAppService.SubmitAppoint(examItemList));
        }

        /// <summary>
        /// 提交预约修改
        /// </summary>
        /// <param name="examItemList"></param>
        /// <returns></returns>
        [HttpPost("/api/manual-appoint/submit-edit")]
        public async Task<IActionResult> SubmitEdit([FromBody] List<SubmitAppointDto> examItemList)
        {
            return new JsonResult(await _manualAppointAppService.SubmitEdit(examItemList));
        }

        /// <summary>
        /// 取消预约
        /// </summary>
        /// <param name="examItemList"></param>
        /// <returns></returns>
        [HttpPost("/api/manual-appoint/cancel")]
        public async Task<IActionResult> Cancel([FromBody]List<SubmitAppointDto> examItemList)
        {
            return new JsonResult(await _manualAppointAppService.Cancel(examItemList));
        }
    }
}
